package org.wm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.wm.domain.SysLogininfor;
import org.wm.response.PageResult;
import org.wm.response.ResponseResult;
import org.wm.service.ISysLogininforService;

import java.util.Arrays;

/**
 * 系统访问记录
 * (已按照 Mybatis-Plus 混合模式进行改造)
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController {
    @Autowired
    private ISysLogininforService logininforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public PageResult<SysLogininfor> list(SysLogininfor logininfor) {
        Page<SysLogininfor> page = getPage();
        // 【修正】调用新的分页方法名
        IPage<SysLogininfor> logininforPage = logininforService.selectLogininforPage(page, logininfor);
        return getDataTable(logininforPage);
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @DeleteMapping("/{infoIds}")
    // 【修正】返回类型改为 ResponseResult<?>
    public ResponseResult<?> remove(@PathVariable Long[] infoIds) {
        // 【修正】调用标准的 removeByIds 方法，它返回 boolean
        boolean result = logininforService.removeByIds(Arrays.asList(infoIds));
        return toAjax(result);
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @DeleteMapping("/clean")
    public ResponseResult<?> clean() {
        logininforService.cleanLogininfor();
        return ResponseResult.success();
    }
}